home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / tcoop.arc / TCOOP2.ARC / GMENUTST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-26  |  3.5 KB  |  128 lines

  1. // gmenutst.cpp: Implements pull-down, tear-away menus in graphics 
  2. // mode. This program is very similar to the text mode program
  3. // in Chapter 11.
  4.  
  5. #include "string.h"
  6. #include "grphscrn.h"
  7. #include "msounit.h"
  8.  
  9. void ExitAction(Wso *, MsgPkt &M)
  10. {
  11.   M.RtnCode = ShutDown;
  12. }
  13.  
  14. void NoAction(Wso *, MsgPkt &) { ; }
  15.  
  16. void PopupAction(Wso *Src, MsgPkt &M)
  17. // Pop-up a window with the name of the object written in it 
  18. {
  19.   Wso *B;
  20.   char Label[80];
  21.  
  22.   strcpy(Label, ((Meso *)(Src))->Name);
  23.   strcat(Label, " Action");
  24.  
  25.   ((Meso *)Src)->OnClose(M);         // Close pull-down window 
  26.   M.Code = M.RtnCode;
  27.   FullScrn->SubMgr->EventStep(M);
  28.   // Open pop-up window 
  29.   B = new Wso(Relief+3, WindowStyle-BorderPrompt, GrphColors);
  30.   B->SetSize(B->Panel->TextWidth(Label), B->Panel->TextHeight(2));
  31.   B->Open(FullScrn, 300, 100); // Hard coded location of pop-up window 
  32.   B->Panel->HzWrt(0, 0, Label, 0);
  33.   B->SwitchFocus(M);
  34.   M.RtnCode = Idle; M.Code = Idle;
  35.   do {                          // Wait until a person closes window 
  36.     B->SubMgr->EventStep(M);    // or pressed ALT-X. 
  37.     M.Code = M.RtnCode;
  38.   } while (!((M.Code == ShutDown) ||
  39.              (B->Active && M.Code == Close && 
  40.              M.Focus == ((Iso *)(B)))));
  41.   if (M.Code == Close) {
  42.      B->OnClose(M);
  43.      Mouse.WaitForEvent(MouseUp, M.Mx, M.My);
  44.      M.RtnCode = Idle;
  45.   }
  46.   delete B;
  47. }
  48.  
  49. // Horizontal pulldown menu
  50. Pmeso *FileBut;
  51. Dmso *FileMenu;
  52. MesoList *FileMList;
  53. Meso *NewBut;
  54. Meso *OpenBut;
  55. Meso *SaveBut;
  56. Meso *CloseBut;
  57. Meso *VtExitBut;
  58. // Edit menu 
  59. Pmeso *EditBut;
  60. Dmso *EditMenu;
  61. MesoList *EditMList;
  62. Meso *CutBut;
  63. Meso *CopyBut;
  64. Meso *PasteBut;
  65. // Action menu 
  66. Pmeso *ActionBut;
  67. Dmso *PanicMenu;
  68. MesoList *PanicMList;
  69. Meso *PanicBut;
  70. Meso *CalmBut;
  71. // Main header menu 
  72. Pmso *Hm;
  73. MesoList *HzMenuList;
  74.  
  75. int Gd, Gm;
  76. int GmenuStyle;
  77. main()
  78. {
  79.   Gd = DETECT;
  80.   Setup(MouseRequired, Gd, Gm, "\\tcpp\\bgi", SANS_SERIF_FONT);
  81.   GmenuStyle = WindowStyle - BorderPrompt;
  82.  
  83.   // Allocate and setup the menu system 
  84.   FileMList = new MesoList();
  85.   NewBut = new Meso("New", PopupAction);
  86.   FileMList->Append(NewBut);
  87.   OpenBut = new Meso("Open", PopupAction);
  88.   FileMList->Append(OpenBut);
  89.   SaveBut = new Meso("Save", PopupAction);
  90.   FileMList->Append(SaveBut);
  91.   CloseBut = new Meso("Close", PopupAction);
  92.   FileMList->Append(CloseBut);
  93.   VtExitBut = new Meso("Exit", ExitAction);
  94.   FileMList->Append(VtExitBut);
  95.   FileMenu = new Dmso(FileMList, 90, Relief+3, GmenuStyle, GrphColors);
  96.  
  97.   EditMList = new MesoList();
  98.   CutBut = new Meso("Cut", PopupAction);
  99.   EditMList->Append(CutBut);
  100.   CopyBut = new Meso("Copy", PopupAction);
  101.   EditMList->Append(CopyBut);
  102.   PasteBut = new Meso("Paste", PopupAction);
  103.   EditMList->Append(PasteBut);
  104.   EditMenu = new Dmso(EditMList, 90, Relief+3, GmenuStyle, GrphColors);
  105.  
  106.   PanicMList = new MesoList();
  107.   PanicBut = new Meso("Panic", PopupAction);
  108.   PanicMList->Append(PanicBut);
  109.   CalmBut = new Meso("Don't Panic", PopupAction);
  110.   PanicMList->Append(CalmBut);
  111.   PanicMenu = new Dmso(PanicMList, 90, Relief+3, GmenuStyle, GrphColors);
  112.  
  113.   HzMenuList = new MesoList;
  114.   FileBut = new Pmeso("File", FileMenu);
  115.   HzMenuList->Append(FileBut);
  116.   EditBut = new Pmeso("Edit", EditMenu);
  117.   HzMenuList->Append(EditBut);
  118.   ActionBut = new Pmeso("Panic", PanicMenu);
  119.   HzMenuList->Append(ActionBut);
  120.   Hm = new Pmso(HzMenuList, 300, 200, 20, 0x33, GmenuStyle, GrphColors);
  121.  
  122.   // Draw a background to the screen 
  123.   Hm->Open(FullScrn, 0, 0);
  124.   Hm->Inner->Panel->Clear(' ', 0x70);
  125.   MainEventLoop();
  126.   CleanUp();
  127. }
  128.